package com.xxl.shoppingapp.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.xxl.shoppingapp.R;


public class CommonActivity extends BaseActivity {

public static String SER_KEY = "SER_KEY";
    public static void show(Context context, Class<? extends Fragment> className) {
        CommonActivity.fragment = fragment;
        Intent intent = new Intent(context, CommonActivity.class);
        context.startActivity(intent);
    }

    private static Fragment fragment;

    public static void showFromFragment(Fragment from, Fragment to) {
        CommonActivity.fragment = to;
        Intent intent = new Intent(from.getActivity(), CommonActivity.class);
        from.startActivity(intent);
    }

    public static void showFromActivity(Activity from, Fragment to, Bundle bundle) {
        CommonActivity.fragment = to;
        Intent intent = new Intent(from, CommonActivity.class);
        intent.putExtras(bundle);
        from.startActivity(intent);
    }


    public static void showFromFragmentFroResult(Fragment from, Fragment to, int requestCode) {
        CommonActivity.fragment = to;
        Intent intent = new Intent(from.getActivity(), CommonActivity.class);
        from.startActivityForResult(intent, requestCode);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_common;
    }

    @Override
    protected void initView() {
        super.initView();
        if (fragment == null) {
            return;
        }
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.real_content, fragment).commit();
    }


}
